package cn.wolfcode.shop.cloud.common;

import lombok.Getter;
import lombok.Setter;

import java.security.SecureRandomSpi;

@Setter
@Getter
public class Result<T> {
    public static final int SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG = "操作成功";
    public static final int DEFAULT_ERROR_CODE = 50001;
    private static final String DEFAULT_ERROR_MSG = "系统故障";
    private String msg;
    private int code;
    private T data;

    public Result(String msg, int code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public Result() {
    }

    public static <T> Result success(T data) {
        return new Result(SUCCESS_MSG, SUCCESS_CODE, data);
    }

    public static Result error(CodeMsg codeMsg) {
        return new Result(codeMsg.getMsg(), codeMsg.getCode(), null);
    }

    public static Result defaultError() {
        return new Result(DEFAULT_ERROR_MSG, DEFAULT_ERROR_CODE, null);
    }

}






